<%--
  Created by IntelliJ IDEA.
  User: Rui
  Date: 2018/9/15
  Time: 13:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    Object num = session.getAttribute("num");
    Object attr = session.getAttribute("attrClass");
    Byte attrClass = 0;
    if (num != null) {
        if (num.equals("1")) {
            session.removeAttribute("attrClass");
            session.removeAttribute("system");
        } else if (num.equals("0")) {
            session.setAttribute("num", "1");
            if (session.getAttribute("attrClass") != null) {
                attrClass = Byte.parseByte(session.getAttribute("attrClass").toString());
            }
        }
    }

%>
<!DOCTYPE html>
<html>
<head>
    <%@include file="../../../../resources/inc/head.jsp" %>
    <style>
        .layui-card-body label {
            width: 115px
        }

        .layui-card-body .layui-input-block {
            margin-left: 145px
        }
    </style>
</head>
<body>

<div class="layui-fluid">


    <div class="layui-card-body">
        <expect-x:tip tipMessage="标识“*”的选项为必填项，其余为选填项。;请按提示信息填写每一个字段"/>
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto option-bar">
                <div class="layui-collapse ">
                    <div class="layui-colla-item">
                        <h2 class="layui-colla-title">设置选项添加</h2>
                       ` <div class="layui-colla-content">
                            <div class="layui-form-item">
                                <input type="hidden" name="id" attrId="attrId" value="${system.id}">

                                <div class="layui-inline">
                                    <input type="text" name="attrName" value="${system.attrName}"
                                           lay-verify="required" lay-verType="tips"
                                           placeholder="输入选项名称(必填)" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-inline">
                                    <expect-x:dictSelect field="attrType" typeGroupCode="form_type"
                                                         defaultVal="${system.attrType}" placeholder="选择选项类型(必填)"/>
                                </div>

                                <div class="layui-inline">
                                    <expect-x:dictSelect field="attrClass" typeGroupCode="web_site"
                                                         defaultVal="${system.attrClass}" placeholder="选择所属模块(必填)"/>
                                </div>
                                <div class="layui-inline">
                                    <textarea style="min-height: 40px" placeholder="输入选项描述" alue="${system.attrDesc}" name="attrDesc"
                                               class="layui-textarea">${system.attrDesc}</textarea>
                                </div>
                                <div class="layui-inline">
                                    <button  class="layui-btn" lay-submit lay-filter="Type-add">
                                        添加
                                    </button>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>
        <div class="layui-tab" lay-filter="systemTab">
            <ul class="layui-tab-title">
                <c:forEach var="systemType" items="${systemTypes}">
                    <li class="layui-this" lay-id="${systemType.typeCode}">${systemType.typeName}</li>
                </c:forEach>
            </ul>
            <div class="layui-tab-content layui-card common-form" id="settingDiv" style="overflow-Y: scroll">
                <c:forEach var="systemType" items="${systemTypes}">
                    <div class="layui-tab-item    ${systemType.typeCode==0?'layui-show':''}">
                        <form class="layui-form" html="">
                            <c:forEach var="systemSetting" items="${systemSetting}">
                                <c:if test="${systemSetting.attrClass==systemType.typeCode}">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label"><a href="##" class="tool"
                                                                           attr_id="${systemSetting.id}">${systemSetting.attrName}</a></label>
                                        <c:if test="${systemSetting.attrType==0}">
                                            <div class="layui-input-inline">
                                                <input type="text" name="${systemSetting.id}"
                                                       value="${systemSetting.attrValue}" lay-verify="title"
                                                       autocomplete="off" placeholder="请输入" class="layui-input">
                                            </div>
                                            <div class="layui-form-mid layui-word-aux">${systemSetting.attrDesc}</div>
                                        </c:if>
                                        <c:if test="${systemSetting.attrType==1}">
                                            <expect-x:dictSelect field="${systemSetting.id}"
                                                                 typeGroupCode="${systemSetting.attrDesc}"
                                                                 defaultVal="${systemSetting.attrValue}" type="radio"/>
                                        </c:if>
                                        <c:if test="${systemSetting.attrType==2}">
                                            <expect-x:dictSelect field="${systemSetting.id}"
                                                                 typeGroupCode="${systemSetting.attrDesc}"
                                                                 defaultVal="${systemSetting.attrValue}"/>
                                        </c:if>
                                        <c:if test="${systemSetting.attrType==3}">
                                            <div class="layui-input-inline">
                                            <textarea placeholder="请输入内容" value="${systemSetting.attrValue}"
                                                      name="${systemSetting.id}"
                                                      class="layui-textarea">${systemSetting.attrValue}</textarea>
                                            </div>
                                            <div class="layui-form-mid layui-word-aux">${systemSetting.attrDesc}</div>
                                        </c:if>
                                        <c:if test="${systemSetting.attrType==4}">
                                            <div class="layui-input-inline">
                                                <c:if test="${systemSetting.attrValue==null}">
                                                    <expect-x:webUploader
                                                            pickerText="上传${systemSetting.attrName}"
                                                            pickerId="setting${systemSetting.id}"
                                                            isLocal="false" width="90"/>
                                                </c:if>
                                                <c:if test="${systemSetting.attrValue!=null}">
                                                    <expect-x:webUploader pickerText="上传${systemSetting.attrName}"
                                                                          fileList="${systemSetting.attrValue}"
                                                                          pickerId="setting${systemSetting.id}"
                                                                          isLocal="false" width="90"/>
                                                </c:if>
                                            </div>
                                        </c:if>
                                    </div>

                                </c:if>
                            </c:forEach>
                                <%--                            <shiro:hasPermission name="Expect-X:system:cron:update">--%>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="add-value">立即提交</button>
                                </div>
                            </div>
                                <%--                            </shiro:hasPermission>--%>
                        </form>
                    </div>
                </c:forEach>
            </div>
        </div>

        <script type="text/html" id="gmtModifiedTpl">
            {{#
            var date = new Date();
            date.setTime(d.gmtModified);
            return date.Format("yyyy-MM-dd hh:mm:ss");
            }}
        </script>


    </div>
</div>
</div>

<%@include file="../../../../resources/inc/footer.jsp" %>
<script>
    layui.config({
        base: '<%=basePath%>resources/lib/layuiAdmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'element'], function () {
        var $ = layui.$
            , form = layui.form
            , table = layui.table
            , element = layui.element;
        var attrClass =<%=attrClass%>;
        $("#settingDiv").css("height", (window.screen.height - 500) + "px");
        element.tabChange('systemTab', attrClass);
        var fn1;
        //删除监听
        $(document).on("click", ".deleteValue", function () {
            var id = $(this).attr("attr_id");

            layer.load(2);

            $.ajax({
                type: "GET",
                url: "<%=basePath%>manager/system/systemSetting/delete.html",
                data: {"id": id},
                success: function (data) {
                    layer.closeAll("loading");
                    data = JSON.parse(data);
                    if (data.success) {
                        layer.msg("删除成功,正在刷新");
                        setTimeout(function () {
                            window.location.reload()
                        }, 1000);
                    } else {
                        layer.msg(data.message);
                    }

                }
            });
        });

        $(document).on("click", ".tool", function () {
            layer.closeAll("tips");
            if (fn1 != undefined) {
                $(document).unbind('click', fn1);
            }
            var id = $(this).attr("attr_id");
            layer.tips('<div class="layui-btn-group"><button class="updateValue   layui-btn layui-btn-primary layui-btn-sm" lay-filter="settingTips" attr_id="' + id + '">\n' +
                '    <i class="layui-icon">&#xe642;</i>\n' +
                '  </button>\n' +
                '  <button class="deleteValue    layui-btn layui-btn-primary layui-btn-sm" lay-filter="settingTips" attr_id=' + id + '>\n' +
                '    <i class="layui-icon">&#xe640;</i>\n' +
                '  </button></div>', $(this), {
                tips: [1, '#ffffff'],
                time: 3000,
                success: function () {
                    $(document).bind('click', fn1 = function () {
                        layer.closeAll("tips");
                    });
                },
                end: function () {

                    $(document).unbind('click', fn1)
                }

            });
        });

        //修改监听
        $(document).on("click", ".updateValue", function () {
            var id = $(this).attr("attr_id");
            layer.load(2);
            $.ajax({
                    type: "GET",
                    url: "<%=basePath%>manager/system/systemSetting/update/" + id + ".html",
                    success: function (data) {
                        layer.closeAll("loading");
                        window.location.reload();
                    },
                }
            );


        })
        //监听添加
        form.on('submit(Type-add)', function (data) {

            var field = data.field;
            var id = field.id;

            if (id == "") {
                layer.load(2);
                $.ajax({
                    url: "<%=basePath%>manager/system/systemSetting/create.html",
                    type: "POST",
                    data: field,
                    dataType: "JSON",
                    success: function (data) {

                        layer.closeAll("loading");
                        if (data.success) {
                            layer.msg("添加成功");
                            setTimeout(function () {
                                window.location.reload()
                            }, 1000);
                        } else {
                            layer.msg(data.message, {icon: 5});
                        }
                    }
                });
            }
            //监听获取数据后的修改
            else {
                layer.load(2);
                $.ajax({
                    type: "POST",
                    url: "<%=basePath%>manager/system/systemSetting/update.html",
                    data: field,
                    dataType: "JSON",
                    success: function (data) {
                        console.log(data);

                        layer.closeAll("loading");
                        if (data.success) {
                            layer.msg("修改成功,正在刷新");
                            setTimeout(function () {
                                window.location.reload()
                            }, 1000);
                        } else {
                            layer.msg(data.message, {icon: 5});
                        }

                    }
                });
            }


        });
        //设置value值
        form.on('submit(add-value)', function (data) {
            var field = data.field;
            layer.load(2);
            $.ajax({
                type: "POST",
                url: "<%=basePath%>manager/system/systemSetting/createValue.html",
                data: {"systemSettingValue": JSON.stringify(field)},
                success: function (data) {

                    data = JSON.parse(data);
                    layer.closeAll("loading");
                    if (data.success) {
                        layer.msg("操作成功,正在刷新");
                        setTimeout(function () {
                            window.location.reload()
                        }, 2000);

                    } else {
                        layer.msg(data.message);
                    }

                }
            });
            return false;
        });


    });

    function edit(e) {

    }

</script>
</body>
</html>

